package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
@Slf4j
public class DtsBrandServiceImpl implements DtsBrandService {

    @Autowired
    DtsBrandMapper brandMapper;

    @Override
    public List<Integer>  getBrandIdsByAdminId(Integer adminId) {
        LambdaQueryWrapper<DtsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsBrand::getAdminId, adminId);
        wrapper.eq(DtsBrand::getDeleted, false);

        List<DtsBrand> brands = brandMapper.selectList(wrapper);

        List<Integer> brandIds = brands.stream().map(brand -> {
            return brand.getId();
        }).collect(Collectors.toList());


        return brandIds;
    }

    @Override
    public List<DtsBrand> selectList(List<Integer> brandIds) {

        LambdaQueryWrapper<DtsBrand> wrapper = new LambdaQueryWrapper<>();
        if(brandIds != null && brandIds.size() > 0){
            wrapper.in(DtsBrand::getId, brandIds);
        }
        wrapper.eq(DtsBrand::getDeleted, false);
        return brandMapper.selectList(wrapper);
    }

    @Override
    public DtsBrand findById(Integer brandId) {
        return brandMapper.selectById(brandId);
    }
}
